package common;

import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.seari.bean.pa.StationState;
import com.seari.commonutils.redis.JedisUtilProxy;
import com.seari.commonutils.redis.ex.JedisNotInitializeException;
import com.seari.utils.DataUtil;
import com.seari.utils.JedisPoolUtils;
import com.seari.utils.PropertiesUtil;
public class RedisData {
	@Test
	public void line12() throws JedisNotInitializeException{
		
		JedisUtilProxy.initJedisPoolUtil("127.0.0.1", 6379);
		Jedis jedis = JedisUtilProxy.getJedis();
		
		/*String str = jedis.get("PaLine12");
		
		System.out.println(str);
		

		List<StationState> parseArray = JSONArray.parseArray(str,StationState.class);
		
		System.out.println(parseArray);
		*/
		
		for (int i = 1; i < 20000; i++) {
			if(i%2 == 1){
				jedis.hset("DI", String.valueOf(i), "0");
			}else{
				
				jedis.hset("DI", String.valueOf(i), "1");
			}
			
			jedis.hset("AI", String.valueOf(i), String.valueOf(i));
		}
		
	}
		
		
		
	
	@Test
	public void redisTest1(){
		Jedis jedis = null;
			jedis = JedisPoolUtils.getJedis();
			
			for (int i = 0; i < 684; i++) {
				
				String hget = jedis.hget("SCADA_DATA", String.valueOf(i));
				System.out.print(i + " : " + hget + "   ,   ");
				
				
				
				
			}
			
		
		
	}
	
	@Test
	public void propertiesDemo() throws Exception{
		// 创建文件解析
		PropertiesUtil prop = new PropertiesUtil();
		prop.load(new InputStreamReader(Client.class.getClassLoader()
				.getResourceAsStream("sendBas.properties"), "UTF-8"));
		// 调用解析工具类 
		List<Object> keys = prop.getKeyList();
		System.out.println(keys.size());
		System.out.println(keys);
		System.out.println("-------------------------");
		byte[] basId = DataUtil.getBasId(keys,0);
		
		for (int i = 0; i < basId.length; i++) {
			System.out.println(basId[i]);
			
		}
		
		
		
	}
	
	@Test
	public void propertiesDemo2() throws Exception{
		
		long start = System.currentTimeMillis();
		
		Properties loadConfig = PropertiesUtil.loadConfig("sendBas.properties");
		
		Set<Object> keySet = loadConfig.keySet();
		
		System.out.println(keySet);
		
		long end = System.currentTimeMillis();
		System.out.println(end - start);
		
	}
	
	

	
	@Test
	public  void  jedisData() {
		 Jedis jedis = null;
			try {
				jedis = JedisPoolUtils.getJedis();
				
				int count = 1;
				for (int i = 0; i <= 700; i++) {

					jedis.hset("SCADA_DATA", String.valueOf(i), "1");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			

			
			
			
			
	}
	
	
@Test
public void Demos(){
	int b = 255;
	String hexString = Integer.toHexString(b);
	
	System.out.println(hexString);
	
	byte bytess = (byte)0xff;
	System.out.println(bytess);
	
	String a = "11111111";
	String str = "0x";
	String binaryString2hexString =binaryString2hexString(a);
	int d = Integer.parseInt((binaryString2hexString).substring(0), 16);
	
	System.out.println(d);
}
	

public static String binaryString2hexString(String binaryString) {
    if (binaryString.length() % 4 != 0) {
        return null;
    }
    String hexString = "";
    int bit = 0;
    for (int i = 0; i < binaryString.length(); i += 4) {
        bit = 0;
        for (int j = 0; j < 4; j++) {
            String x = binaryString.substring(i + j, i + j + 1);
            bit += Integer.parseInt(x) << (4 - j - 1);
        }
        hexString += Integer.toHexString(bit);
    }
    return hexString.toString();
}

	
	

}
